package com.link.play.fit.ai

import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.ktx.remoteConfig

/**
 *Create by SleepDog on 2025-04-12
 * firebase remote config
 */
object RemoteConfig {

    var noVipCanIn = true
        //无vip可进首页
//        get() {
//            //先尝试更新
//            Firebase.remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
//                if (task.isSuccessful) {
//                    noVipCanIn =
//                        Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_VIP_SWITCH)
//                }
//            }
//            //立刻返回当前值
//            field = Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_VIP_SWITCH)
//            return field
//        }

    var vipNeedPlanPay = false
        //vip是否需要购买支付定制计划
//        get() {
//            //先尝试更新
//            Firebase.remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
//                if (task.isSuccessful) {
//                    vipNeedPlanPay =
//                        Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_VIP_PLAN_PAY)
//                }
//            }
//            //立刻返回当前值
//            field = Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_VIP_PLAN_PAY)
//            return field
//        }

    var isWeightControlGuide = false
//        get() {
//            //先尝试更新
//            Firebase.remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
//                if (task.isSuccessful) {
//                    isWeightControlGuide =
//                        Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_WEIGHT_CONTROL_GUIDE)
//                }
//            }
//            //立刻返回当前值
//            field =
//                Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_WEIGHT_CONTROL_GUIDE)
//            return field
//        }

//    var isShowAd = false
//        //显示广告
//        get() {
//            //先尝试更新
//            Firebase.remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
//                if (task.isSuccessful) {
//                    vipNeedPlanPay =
//                        Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_IS_SHOW_AD)
//                }
//            }
//            //立刻返回当前值
//            field = Firebase.remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_IS_SHOW_AD)
//            return field
//        }

    var daysCaloriePlan = 30
        //定制计划天数
//        get() {
//            //先尝试更新
//            Firebase.remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
//                if (task.isSuccessful) {
//                    daysCaloriePlan =
//                        Firebase.remoteConfig.getLong(GlobalConfig.REMOTE_CONFIG_VIP_DAYS_CALORIE_PLAN)
//                            .toInt()
//                }
//            }
//            //立刻返回当前值
//            field = Firebase.remoteConfig.getLong(GlobalConfig.REMOTE_CONFIG_VIP_DAYS_CALORIE_PLAN)
//                .toInt()
//            return field
//        }

    var vipProductWeek: String = "vip_week"
    var vipProductYear: String = "vip_year"

    var vipProductYearDiscount: String = "vip_year_discount"

    var vipProductCaloriePlan: String = "vip_exercise_plan_month"
    var vipProductCaloriePlanYear: String = "vip_exercise_plan_year"

    fun init() {
        val remoteConfig = Firebase.remoteConfig
        //更新值
        Firebase.remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
            if (task.isSuccessful) {

                noVipCanIn = remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_VIP_SWITCH)
                vipNeedPlanPay = remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_VIP_PLAN_PAY)
                vipProductWeek = remoteConfig.getString(GlobalConfig.REMOTE_CONFIG_VIP_PRODUCT_WEEK)
                vipProductYear = remoteConfig.getString(GlobalConfig.REMOTE_CONFIG_VIP_PRODUCT_YEAR)
                vipProductYearDiscount =
                    remoteConfig.getString(GlobalConfig.REMOTE_CONFIG_VIP_PRODUCT_YEAR_DISCOUNT)
                vipProductCaloriePlan =
                    remoteConfig.getString(GlobalConfig.REMOTE_CONFIG_VIP_PRODUCT_CALORIE_PLAN)
                vipProductCaloriePlanYear =
                    remoteConfig.getString(GlobalConfig.REMOTE_CONFIG_VIP_PRODUCT_CALORIE_PLAN_YEAR)
                daysCaloriePlan =
                    Firebase.remoteConfig.getLong(GlobalConfig.REMOTE_CONFIG_VIP_DAYS_CALORIE_PLAN)
                        .toInt()
                isWeightControlGuide =
                    remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_WEIGHT_CONTROL_GUIDE)
               // isShowAd = remoteConfig.getBoolean(GlobalConfig.REMOTE_CONFIG_IS_SHOW_AD)
            }
        }
    }
}